<template>
  <!-- 重置密码dialog -->
  <el-dialog title="出入库记录" :visible.sync="visible" width="60%">
    <el-tabs
      v-model="queryParams.type"
      type="card"
      @tab-click="handelChangeType"
    >
      <el-tab-pane label="入库" name="0"></el-tab-pane>
      <el-tab-pane label="出库" name="1"></el-tab-pane>
    </el-tabs>
    <el-form
      :model="queryParams"
      ref="queryParams"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item
        :label="queryParams.type == '0' ? '入库时间' : '出库时间'"
        prop="repairTime"
        clearable
      >
        <el-date-picker
          v-model="times"
          placeholder="请选择"
          type="datetimerange"
          range-separator="~"
          style="width: 340px"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item
        label="供应商名称"
        prop="supplierName"
        v-if="queryParams.type == '0'"
        label-width="120px"
      >
        <el-input
          v-model.trim="queryParams.supplierName"
          placeholder="请输入供应商名称"
          style="width: 137px"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="teamList"
      v-if="queryParams.type == '0'"
    >
      <el-table-column label="时间" align="center" prop="ctime" />
      <el-table-column label="订单ID" align="center" prop="orderId" />
      <el-table-column label="运输单ID" align="center" prop="partsName" />
      <el-table-column label="原料名称" align="center" prop="rawMaterialName" />
      <el-table-column label="供应商名称" align="center" prop="supplierName" />
      <el-table-column label="仓库名称" align="center" prop="inventoryName" />
      <el-table-column label="入库数量（吨）" align="center" prop="num" />
    </el-table>
    <el-table
      v-loading="loading"
      :data="teamList"
      v-if="queryParams.type == '1'"
    >
      <el-table-column label="时间" align="center" prop="ctime" />
      <el-table-column label="订单ID" align="center" prop="orderId" />
      <el-table-column label="运输单ID" align="center" prop="partsName" />
      <el-table-column label="原料名称" align="center" prop="rawMaterialName" />
      <el-table-column label="供应商名称" align="center" prop="supplierName" />
      <el-table-column label="仓库名称" align="center" prop="inventoryName" />
      <el-table-column label="出库数量（吨）" align="center" prop="Double" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <span slot="footer" class="dialog-footer">
      <el-button @click="handelCancel">关 闭</el-button>
      <!-- <el-button type="primary" @click="handleSubmit">确 定</el-button> -->
    </span>
  </el-dialog>
</template>
  <script>
import { updateUser } from "@/api/system/user";
import QuickFilterDate from "@/components/QuickFilterDate";
import { inventoryRecord } from "@/api/service/inventory";
export default {
  components: {
    QuickFilterDate,
  },
  data() {
    return {
      initObj: {},
      visible: false,
      changeForm: {
        kc: "",
      },
      rules: {
        kc: [
          {
            required: true,
            message: "请输入",
            trigger: "change",
          },
        ],
      },

      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 排班管理表格数据
      teamList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: "1",
        startTime: null,
        endTime: null,
        supplierName: null,
        concreteId: null,
        engineeringName: null,
      },
      times: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  props: {},
  computed: {},
  methods: {
    handelChangeType(val) {
      this.resetQuery();
    },
    // 初始化函数--->父级调用
    handelInit(val) {
      console.log(val);
      this.initObj = val;
      this.visible = true;
      this.queryParams.type = "0";
      this.queryParams.id = val.id;
      this.getList();
    },
    handelCancel() {
      this.$refs.queryParams.resetFields();
      this.visible = false;
    },
    handleSubmit() {},
    /** 查询排班管理列表 */
    getList() {
      this.loading = true;
      inventoryRecord({
        ...this.queryParams,
        startTime: this.times?.[0],
        endTime: this.times?.[1],
      }).then((response) => {
        console.log("response--->", response);
        let { records, total } = response.data;
        this.teamList = records;
        this.total = total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.startTime = null;
      this.queryParams.endTime = null;
      this.resetForm("queryForm");
      this.times = [];
      this.handleQuery();
    },
  },
};
</script>